package cn.wbnull.springbootdemo.xiancehng;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;

/**
 * 功能描述
 *
 * @author EDZ
 * @since 2022-08-16
 */
class MoreThread {
    //callable线程池
    public static void main(String[] args) throws Exception{
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,4,10, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        Future<String> f1 = pool.submit(new MyThreadCallable());
        Future<String> f2 = pool.submit(new MyThreadCallable());
        Future<String> f3 = pool.submit(new MyThreadCallable());
        Future<String> f4 = pool.submit(new MyThreadCallable());
        System.out.println(f1.get());
        System.out.println(f2.get());
        System.out.println(f3.get());
        System.out.println(f4.get());
    }
//线程实现Callable接口
public static class MyThreadCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName()+"正在工作中~";
    }
}


}
